package com.fingard.dsp.bank.directbank.gdb01.util;

import java.io.File;

import com.fingard.dsp.bank.directConfig.BankConfig;
import com.fingard.text.StringHelper;

public class ReceiptProp {

    /**
     * 银行上传目录方式
     */
    private String uploadPathType = "acct";

    /**
     * 第一列取数
     */
    private String columnField1 = "qryAcct";

    /**
     * 第二列取数
     */
    private String columnField2 = "bankNo";

    /**
     * 第三列取数
     */
    private String columnField3 = "corpNo";

    /**
     * 第四列取数
     */
    private String columnField4 = "transChannel";

    /**
     * 第五列取数
     */
    private String columnField5 = "CDFlag";

    /**
     * 第六列取数
     */
    private String columnField6 = "oppAcct";

    /**
     * 汇总文件命名方式
     */
    private String sumFileNameType = "acct";

    public ReceiptProp(BankConfig bankConfig) {
        try {
            if (bankConfig != null) {
                uploadPathType = bankConfig.getMapValueByKey("receiptBankInfo", "uploadPathType");
                columnField1 = bankConfig.getMapValueByKey("receiptBankInfo", "columnField1");
                columnField2 = bankConfig.getMapValueByKey("receiptBankInfo", "columnField2");
                columnField3 = bankConfig.getMapValueByKey("receiptBankInfo", "columnField3");
                columnField4 = bankConfig.getMapValueByKey("receiptBankInfo", "columnField4");
                columnField5 = bankConfig.getMapValueByKey("receiptBankInfo", "columnField5");
                columnField6 = bankConfig.getMapValueByKey("receiptBankInfo", "columnField6");
                sumFileNameType = bankConfig.getMapValueByKey("receiptBankInfo", "sumFileNameType");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public int getQryAcctIndex() {
        return getIndex("qryAcct");
    }

    public int getBankNoIndex() {
        return getIndex("bankNo");
    }

    public int getCorpNoIndex() {
        return getIndex("corpNo");
    }

    public int getTransChannelIndex() {
        return getIndex("transChannel");
    }

    public int getCDFlagIndex() {
        return getIndex("CDFlag");
    }

    public int getOppAcctIndex() {
        return getIndex("oppAcct");
    }

    private int getIndex(String indexFlag) {
        if (columnField1.equals(indexFlag)) {
            return 0;
        } else if (columnField2.equals(indexFlag)) {
            return 1;
        } else if (columnField3.equals(indexFlag)) {
            return 2;
        } else if (columnField4.equals(indexFlag)) {
            return 3;
        } else if (columnField5.equals(indexFlag)) {
            return 4;
        } else if (columnField6.equals(indexFlag)) {
            return 5;
        } else {
            return -1;
        }
    }

    public String getFilePath(String p_pathPrefix, String p_acctNum, String p_date8Format) {
        if (p_pathPrefix == null) {
            p_pathPrefix = "";
        }
        String filePath = StringHelper.trimEndFileSp(p_pathPrefix) + File.separator;
        if (uploadPathType.equals("acct")) {
            filePath = filePath + p_acctNum + File.separator + p_date8Format + File.separator;
        } else {
            filePath = filePath + p_date8Format + File.separator;
        }
        return filePath.replaceAll("\\\\", "/");
    }

    public String getSumFileName(String p_acctNum, String p_date8Format) {
        String fileName = "";
        if (sumFileNameType.equals("acct")) {
            fileName = p_acctNum + ".txt";
        } else {
            fileName = p_date8Format + ".txt";
        }
        return fileName;
    }

    public String getSumFileFullPath(String p_pathPrefix, String p_acctNum, String p_date8Format) {
        String filePath = getFilePath(p_pathPrefix, p_acctNum, p_date8Format);
        filePath = filePath + getSumFileName(p_acctNum, p_date8Format);
        return filePath.replaceAll("\\\\", "/");
    }


}
